package com.ayi.bean;

import com.ayi.dao.cartdao.QueryCart;
import com.ayi.utils.GetConn;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author Ayingzz
 * @create 2021/11/28 13:17
 */
public class Book {

    int id; // 图书id
    String name; // 书名
    String author; // 作者
    String type; // 类型
    String details; // 详情
    double price; // 单价
    int currentNum; // 某个用户购物车中 此书的数量
    int inventory; // 库存
    String imgPath; // 图片路径

    public Book(){
    }

    /**
     * 根据图书id和用户名，初始化一本书的同时找到它在此用户下的购买数量
     * @param username
     * @param id
     */
    public Book(String username, int id) {
        setCurrentNum(new QueryCart().initBookWithSettingNum(username, id));
    }

    public Book(int id, String name, String author, String type, String details, double price, int inventory) {
        this.id = id;
        this.name = name;
        this.author = author;
        this.type = type;
        this.details = details;
        this.price = price;
        this.inventory = inventory;
    }

    public int getOne(){
        return 1;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDetails() {
        return details;
    }

    public void setDetails(String details) {
        this.details = details;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double prices) {
        this.price = prices;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getCurrentNum() {
        return currentNum;
    }

    public void setCurrentNum(int currentNum) {
        this.currentNum = currentNum;
    }

    public int getInventory() {
        return inventory;
    }

    public void setInventory(int inventory) {
        this.inventory = inventory;
    }

    public String getImgPath() {
        return imgPath;
    }

    public void setImgPath(String imgPath) {
        this.imgPath = imgPath;
    }


    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String toStringCartBuild() {
        return id + "=1#";
    }

    @Override
    public String toString() {
                return "#Book{" +
                "id=" + id +
                ", name=" + name +
                ", type=" + type +
                ", details=" + details +
                ", prices=" + price +
                ", }";
    }
}
